/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.app.exceptions.AlbumRatingException;
import com.startup.musicstore.app.facade.Facade;
import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.MarketingInformation;
import com.startup.musicstore.model.Review;
import com.startup.musicstore.services.AlbumRatingService;
import com.startup.musicstore.services.crud.AlbumCrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author aljay19
 */
@Service("albumRatingService")
@Transactional
public class AlbumRatingServiceImpl implements AlbumRatingService {

    private Facade data = new Facade();

    @Override
    public int getRating(Long albumID) {

        AlbumCrudService albumCrudService = data.getAlbumCrudService();

        Album album = albumCrudService.findById(albumID);

        MarketingInformation marketingInformation = album.getmarketingInformation();
        if (marketingInformation.getStatusOfMarketingInformation().equalsIgnoreCase("Pending")) {
            throw new AlbumRatingException("No rating has been set for this album");
        } else {
            Review review = marketingInformation.getReview();
            return review.getRating();

        }
    }
}
